<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<title>_订单打印</title>


<script type="text/javascript">
 
$(function() {
	  $("#txt_orderno").focus();
});

var curOrderno;
var taskCode="";//拣货任务号

function reset(){
	  $("#txt_info").html('');
	  $("#txt_orderno").focus();
	  $("#msg_sku").html("");
	  $("[name='exist']").hide();
    $("[name='noexist']").show();
}

//验证
function change_sku(){

	  var orderno=$("#txt_orderno").val().trim();
	  if(orderno==''){
		  $("#msg_sku").html("请录入订单编号!"); 
	  }
	  var info=$("#txt_info").html();
	  if(info.length>0){
		  info+=";";
	  }
	  info+=orderno;
	  $("#txt_info").html(info);
	  
	  $.ajax({
			type:'post',
			url:'${ctx}/v2/express/ajaxCheckOrderInfo',
			data:{
				orderno:orderno
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
				if(msg=='success'){
					$("#msg_sku").css("color","green");
					$("#msg_sku").html("订单匹配成功，请打印运单...");
					$("#txt_orderno").blur();
					taskCode=data.workOrder.taskCode;
					
					//显示订单信息
					var workOrder=data.workOrder;
				    showOrderInfo(workOrder);
				    curOrderno=workOrder.order.ordeno;
				    
				    //加载运单模板
				    var expressStyles=data.expressStyles;
				    var temp="<option value=''></option>";
				    $.each(expressStyles,function(i,obj){
				       temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
				    });
				    //$("[name='expressStylesId']").html(temp);
				    /* packFormPrinter(packFormPrinter) ;
				    packFormPrinter(expressStylesId) ; */
				    $("#expressStylesId").html(temp) ;
				    $("#expressStylesId").trigger("chosen:updated");
				    /* //加载随箱单模板
				    var packformStyles=data.packformStyles;
				    var _temp="";
				    $.each(packformStyles,function(i,obj){
				       _temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
				    });
				    $("#packformStylesId").html(_temp);
				    $("#packformStylesId").trigger("chosen:updated"); */
				}else if(msg=='cancel'){
				    $("#msg_sku").css("color","red");
					$("#msg_sku").html("此单是取消单，请拦截勿包装！");
					
					//显示订单信息
					var workOrder=data.workOrder;
				    showOrderInfo(workOrder);
				    
				    
				    $("#btn_print_ebill").hide();
  	            $("#btn_print_cbill").hide();
  	            $("#btn_print_boxbill").hide();
  	            $("#btn_pkg").hide();
  	            $("#txt_info").html("");
  	            
				    
				}else{
				    $("[name='exist']").hide();
                  $("[name='noexist']").show();
                  $("#msg_sku").html("");
				}
				
				
				
				$("#txt_orderno").focus();
				$("#txt_orderno").val('');
				
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
	  
}

//显示运单信息
function showOrderInfo(workOrder){
     $("[name='exist']").show();
     $("[name='noexist']").hide();
     
     $("#orderno").html(workOrder.order.ordeno);
     $("#expressNo").html(workOrder.expressNo);
     $("#expressName").html(workOrder.order.cacode);
     $("#address").html(workOrder.order.addres);
     $("#area").html(workOrder.order.provna+"/"+workOrder.order.cityna+"/"+workOrder.order.distna);
     $("#postco").html(workOrder.order.postco);
     $("#recena").html(workOrder.order.recena);
     $("#mobile").html(workOrder.order.mobile);
     $("#teleph").html(workOrder.order.teleph);
     $("#task_code").val(workOrder.taskCode);
     $("#orderno_code").val(workOrder.order.ordeno) ;
     $("#btn_pkg").show();
     
     //订单明细
     var str='';
     $.each(workOrder.order.orderItems,function(i,orderItem){
        str+="<tr name='exist'>";
        str+="<td>"+(i+1)+"</td>";
        str+="<td>"+orderItem.sku+"</td>";
        str+="<td>"+orderItem.qty+"</td>";
        str+="</tr>";
     });
     $("#orderItems").html(str);
}
  
  //单件
  function print(taskCode){
     alert(taskCode);
  }
  
  //重新打印
  function reprint(taskCode){
     alert(taskCode);
  }
  
    var packformStyleId = 0;
	var number = 50;//每次打印的数量
	var workIds = "0";
	var nextOrdeno = "begin";//打印最后一个订单号
	var packStyleName = "OSA-A5";//随箱单名称
	var packStyleType = "A5";//随箱单类型
	var printName = "";//打印机名称
	var expressRex="";//运单号正则表达式
    var workId=0;
    var taskCode="";
	var packFormStylePage = "";
	var expressId=0;
	var expressType="normal";
	
	var succedOrdenos="";
	var pageExpressOrdenos="";
	var firstExpress="";//起始快递单号
	var endExpress="";//终止快递单号

	function ajaxPackFormCount() {
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPackFormCount',
			data : 'workIds=' + workIds + '&number=' + number,
			dataType : 'json',
			success : function(data) {
				if (data.status == 1) {
					packFormStylePage = data.content;
				}
			},

			error : function() {

			}
		});
	}

	function ajaxExpressCount(workId,firstExpress,expressID,printName) {
		 showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxExpressCount',
			data : {
				workIds:workId,
				number:number,
				firstExpress:firstExpress,
				expressID:expressID
				
			},
			dataType : 'json',
			success : function(data) {
				if (data.status == 1) {
					 
					pageExpressOrdenos = data.content;
					 var pageLists=pageExpressOrdenos.split(",");
					    for(var i=0;i<pageLists.length;i++){
					    	if(""==pageLists[i]){
					    		continue;
					    	}
					    	$.ajaxQueue.offer({
								type : 'post',
								url : '${ctx}/print/ajaxPrintQueueExpress',
								data :{
									queues:pageLists[i],
									expressId:expressId
								} ,
								dataType : 'json',
								success : function(data) {

								},
								beforeSend : function(jqXHR, settings) {

								},
								success : function(data, textStatus, jqXHR) {
									if (data.status == "1") {
										$.each(data.content,function(i){
											     var str=data.content[i].content;
												 str=str.replace(/\r\n|\n|\r/g,"");
											     printExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].taskName,data.content[i].expressNo,data.content[i].ordeno,data.content[i].companyCode);
											});
										if(data.index=="finish"){
											 showExpressWork(workId);
											closeBg();
											
										}
									} else {
										alert(data.content);
									}
									
								}
							});
					    }
					
				}else{
					alert(data.content);
					closeBg();
				}
			},

			error : function() {

			}
		});
	}
	
	function printAjaxGuarantee(){
		printName = $("#guaranteeStylePrint").val();
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPrintGuarantee',
			data : {
				taskCode:taskCode
			},
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
						$.each(data.workOrders,function(i,v){
							printGuarantee(v,printName);
						});
						
					updateGuanteeStatus(taskCode);
					} else {
						closeBg();
					}
				 }
		});
	}
	
	function updateGuanteeStatus(taskCode){
		$.ajax({
			type : 'post',
			url : '${ctx}/print/updateGuarantee',
			data : {
				taskCode:taskCode
			},
			dataType : 'json',
			success : function(data){
			if (data.status == "1") {
					 closeBg();
				} else {
					alert(data.content);
				}
			},
			error : function() {
					closeBg();
			}
		});
	}
	
	function ajaxEbillExpressCount(taskCode,expressID,printName) {
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/print/spliteEbillOrder',
			data : {
				taskCode:taskCode,
				size:number
			},
			dataType : 'json',
			success : function(data) {
				if (data.status == 1) {
					pageExpressOrdenos = data.content;
					 var pageLists=pageExpressOrdenos.split(";");
					    for(var i=0;i<pageLists.length;i++){
					    	if(""==pageLists[i]){
					    		continue;
					    	}
					    	if(pageLists[i]=="finish"){
					    		showExpressWork(workId);
					    		continue;
					    	}
					    	$.ajaxQueue.offer({
								type : 'post',
								url : '${ctx}/print/ajaxPrintEBillExpress',
								data :{
									ordenos:pageLists[i],
									expressId:expressID,
									taskCode:taskCode
								},
								dataType : 'json',
								success : function(data) {
									 if (data.status == "1") {
										 if(data.openCaiNiao == "1"){
										 	//初始化菜鸟控件
											initCNPrint();
										 }
										$.each(data.content, function(i) {
											    var str=data.content[i].content;
											    str=str.replace(/\r\n|\n|\r/g,"");
											    if(data.openCaiNiao == "1"){
											    	printMailExpressByCaiNiao(printName,data.width,data.height,data.expressStyle,data.content[i]);
											    }else if("YUNDA"==data.expressStyle.logisticsCompany.companyCode){
											    	printYunDa(data.content[i].content,printName);
											    }else{
											    	//alert(data.content[i].taskName+"======="+data.content[i].expressNo+"========"+data.content[i].ordeno) ;
											    	//return ;
											    	var orderno_code = $("#orderno_code").val() ;
											    	if(orderno_code == data.content[i].ordeno){
											    		//alert(data.content[i].customerCode) ;
											    		printMailExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].expressNo,data.expressStyle,data.content[i].ordeno);
											    		/*打印订单条码测试，测试完毕屏蔽*/
											    		//printMailExpressDg(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].expressNo,data.expressStyle,data.content[i].ordeno,data.content[i].customerCode);
											    	}else{
											    		//alert(orderno_code+"!="+data.content[i].ordeno) ;
											    	}
											    	return ;
											    }
										});
									    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
									} else if (data.status == "-3") {
										alert("请输入正确的运单号！");
									} else if (data.status == "0") {
										alert(data.content);
									}
									closeBg();
								},
								error : function() {
								}
							});
					    }
				}else{
					alert(data.content);
					closeBg();
				}
			},

			error : function() {
					closeBg();
			}
		});
	}

////////////////准备删除////////////////////
function printFivePackStyleLove(taskName, printerName, printContent,ordeno, rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);

		LODOP.ADD_PRINT_BARCODE(20, 50, 350, 40, "128B", ordeno);
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function printFivePackStyleRy(taskName, printerName, printContent, ordeno,rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);

		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		LODOP.ADD_PRINT_BARCODE(20, 50, 350, 40, "128B", ordeno);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function printFivePackStyle(taskName, printerName, printContent, ordeno,expressNo,rankno,customerCode) {
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A5") ;
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(60, 0, "100%", "100%", strCenterStyle+ printContent);
		LODOP.ADD_PRINT_BARCODE(420, 50, 250, 40, "128B", ordeno);
		if(customerCode=="SUN"){
			LODOP.ADD_PRINT_BARCODE(480, 50, 0, 0, "128B", rankno);
		}else{
			LODOP.ADD_PRINT_BARCODE(10, 10, 0, 0, "128B", rankno);
		}
		
		//LODOP.ADD_PRINT_BARCODE(100, 50, 350, 40, "128B", expressNo);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
		
	}

	function printFourPackStyle(taskName, printerName, printContent, ordeno,expressNo, rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);

		LODOP.ADD_PRINT_BARCODE(10, 50, 350, 50, "128B", ordeno);
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function printStyle(packStyleName,taskName, printerName, printContent, ordeno, expressNo,rankno,customerCode) {
		
			printFivePackStyle(taskName, printerName, printContent, ordeno,expressNo,rankno,customerCode);
		
	}
	
	function printFivePackStyleHS1(taskName, printerName, printContent, ordeno,rankno) {
		LODOP.PRINT_INIT(taskName);
		LODOP.ADD_PRINT_TEXT(10, 10, 200, 20, rankno);

		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(30, 0, "100%", "100%", strCenterStyle+ printContent);
		LODOP.ADD_PRINT_BARCODE(10, 50, 380, 40, "128B", ordeno);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}
	//////////////////////////


	function myCheckedAllTWS() {
		var tempChecked = "";
		$("input[type='checkbox'][name='myChecked']:checked").each(function() {
			if (tempChecked == "") {
				tempChecked = $(this).val();
			} else {
				tempChecked = tempChecked + ":" + $(this).val();
			}
		});
		return tempChecked;
	}

	function changeCode() {
		var customerCode = $("#customers").val();
		window.location.href = "${ctx}/print/pageWorkBatchPrint/${lineType}/"+ customerCode;
	}

	

	function myCheckedAll() {
		var check = $("input[name='myChecked']");
	        check.each(function(n) {
	        if (check.eq(n).attr("disabled") != "disabled") {
	             check.eq(n).attr("checked",$("#myCheckedAll").is(":checked"));
	         }
	       });
		
	}

	function myChecked(item) {
		if ($(item).is(":checked")) {
		} else {
			$("#myCheckedAll").attr("checked", false);
		}
	}

	function printPackForm(item) {

		workIds = myCheckedAllTWS();
		if (workIds == "") {
			$("#message").html("请选择流水号");
			$("#message").show();
			$(item).attr("href", "ss");
			workIds="0";
			hideMessage();
			return false;
		} else {
			$(item).attr("href", "#printAllPackFormStyle");
		}
		
		ajaxPackFormCount();
		packFormPrinter("packFormStylePrint");
		
	}
	
	
	
	function printInitExpress(item){
	   workId=item;
	   packFormPrinter("expressPrint");
	}
	
	function printInitGuarantee(item){
		taskCode=item;
		packFormPrinter("guaranteeStylePrint");
	}

	function printPackFormStyle() {
		showBg();
		workNoAjaxPrinter();
	}
	
	function initFirstExpress(code){
		$("#firstExpressNumber").val("");
		taskCode = code;
	}
	
	function pageAjaxPrintExpress(){
		var firstExpress = $("#firstExpressNumber").val();//运单号
		var esiValue = $("#expressStylesId").val();
		if(!esiValue){
			alert("请选择快递单");
			return;
		}
	    printName = $("#expressPrint").val();
	      if("normal"==expressType){
	        if(!verify(firstExpress)){
	           alert("请输入正确的订单号！");
	           return;
	         }  
	        ajaxExpressCount(workId,firstExpress,expressId,printName);
	      }else if("mail"==expressType){
	    	  var taskCode = $("#task_code").val() ;
	    	ajaxEbillExpressCount(taskCode,expressId,printName);
	      }else{
	    	ajaxExpressCount(workId,firstExpress,expressId,printName);
	      }
	      
	}
	
	
	
	function printWorkExpress(){
	      var firstExpress = $("#firstExpressNumber").val();//运单号
	      if("normal"==expressType){
	        if(!verify(firstExpress)){
	           alert("请输入正确的订单号！");
	           return;
	         }  
	      }
	      
	      printName = $("#expressPrint").val();
	      showBg();
	$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPrintPackExpress',
			data : 'workId=' + workId+'&firstExpress='+firstExpress+'&expressId='+expressId+'&printName='+printName,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					$.each(data.content,function(i){
					   var str=data.content[i].content;
						    str=str.replace(/\r\n|\n|\r/g,"");
							printExpress(data.content[i].taskName,data.content[i].printerName,str,data.width,data.height,data.content[i].taskName,data.content[i].expressNo,data.content[i].ordeno,data.content[i].companyCode);
					
					});
				   ajaxSuccedOrdenos();
                   showExpressWork(workId);
				} else {
					alert(data.content);
				}
				closeBg();
				$("#firstExpressNumber").val("");
			},

			error : function() {

			}
		});
	}
	
	 function ajaxSuccedOrdenos() {
			$.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxSuccedOrdenos',
				data : 'ordenos=' + succedOrdenos,
				dataType : 'json',
				success : function(data) {
					ajaxSuccedOrdenos="";
				},
				error : function() {
					alert("服务器异常2");
				}
			});
		}
	 
	 //修改订单的快递单打印状态
	 function ajaxPrintExpressOrdeno(ordeno,expressNo,companyCode) {
			$.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxPrintExpressOrdeno',
				data : {
					ordeno:ordeno,
					expressNo:expressNo,
					companyCode:companyCode
				},
				dataType : 'json',
				success : function(data) {
					if(data.status=="1"){
						ajaxSuccedOrdenos+=ordeno;
					}
				},
				error : function() {
					alert("服务器异常3");
				}
			});
		}
	
	function showExpressWork(work){
		var lists=work.split(":");
		for(var i=0;i<lists.length;i++){
			 $("#express_"+lists[i]).attr("disabled","disabled");
			 if($("#check"+lists[i]).attr("disabled") == "disabled"){
				 $("#pendPackForm_"+lists[i]).remove();
			 }else{
				 $("#expressStyle"+lists[i]).html("<font color='red'>已打印快递单</font>");
			 }
		}
	   
	   
	}
	//打印快递单
	function printExpress(taskName,printerName,content,width,height,rankno,expressNo,ordeno,companyCode) {
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(1,width,height,""); 
		//LODOP.ADD_PRINT_TEXT(10,10,200,60,rankno);
		//LODOP.ADD_PRINT_BARCODE(10, 200, 180, 40, "128B", expressNo);//打印出快递运单条码，测试后删除。
		eval(content);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			var item=LODOP.PRINT(); 
			if(item){
				ajaxPrintExpressOrdeno(ordeno,expressNo,companyCode);
			}
		}
	}
	
function printGuarantee(workOrder,printName){
		LODOP.PRINT_INIT(workOrder.order.ordeno);
		LODOP.SET_PRINT_PAGESIZE(1,2400,1399,""); 
		var height=0;
		LODOP.ADD_PRINT_TEXT(90,'120mm',140,40,workOrder.taskCode+"_"+workOrder.rankno);
		LODOP.ADD_PRINT_TEXT(120,'120mm',140,40,"商业");
		LODOP.ADD_PRINT_TEXT(120,'50mm',140,40,new Date().Format("yyyy-MM-dd hh:mm:ss"));
		var count = 0;
		var order = workOrder.order.orderItems;
		for(var i =0;i<order.length;i++){
			height = height+30;
			LODOP.ADD_PRINT_TEXT(200+height,'50mm',140,40,order[i].nam);
			LODOP.ADD_PRINT_TEXT(200+height,'120mm',140,80,order[i].des);
			LODOP.ADD_PRINT_TEXT(200+height,'140mm',140,40,order[i].qty);
			LODOP.ADD_PRINT_TEXT(200+height,'160mm',140,80,order[i].pri);
			LODOP.ADD_PRINT_TEXT(200+height,'180mm',140,40,(order[i].pri)*(order[i].qty));
			count+=(order[i].pri)*(order[i].qty);
		}
		LODOP.ADD_PRINT_TEXT(390,'150mm',40,40,count);
		LODOP.ADD_PRINT_TEXT(440,'50mm',40,40,"梁欣");
		LODOP.ADD_PRINT_TEXT(440,'100mm',40,40,"梁欣");
		LODOP.ADD_PRINT_TEXT(440,'120mm',250,100,"佛山市顺德区盈丰行网络科技有限公司");
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
	}

	function workNoAjaxPrinter() {
		packformStyleId = $("#packformStylesId").val();//随箱单样式
		printName = $("#packFormStylePrint").val();
		var count = packFormStylePage.split(":");
		 showBg();
		for ( var i = 0; i < count.length; i++) {
		    var temp=count[i];
		   if(""==temp){
		     continue;
		   }
			$.ajaxQueue.offer({
				type : 'post',
				url : '${ctx}/print/ajaxPrintPackForm',
				data :{
					workIds:workIds,
					number:number,
					nextOrdeno:count[i],
					packformStyleId:packformStyleId,
					printName:printName
				} ,
				dataType : 'json',
				success : function(data) {

				},
				beforeSend : function(jqXHR, settings) {

				},
				success : function(data, textStatus, jqXHR) {
					if (data.status == "1") {
						$.each(data.content, function(i) {
						   if(data.content[i].ordeno=="0"){
						     printWorkBatch(data.content[i].taskName,printName, data.content[i].content,data.content[i].taskName);
						     //修改随箱单状态
						     ajaxWorkTaskPrintStatus(data.content[i].taskName);
						   }else{
						     printStyle(packStyleName,data.content[i].taskName ,printName, data.content[i].content,data.content[i].ordeno,data.content[i].expressNo,data.content[i].taskName,data.content[i].customerCode);
						   }
							
						});
                      if(data.index=="finish"){
                    	 ajaxWorkTaskPackFormStatus(workIds);
                         closeBg();
                
                      }
					} else {
						
						alert(data.content);
					}
					
				}
			});
		}
       
	}
	
	function ajaxWorkTaskPrintStatus(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxWorkTaskPrintStatus',
			data : 'taskCode=' + item,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					   var id=data.content.id;
					
					   $("#check"+id).attr("disabled",true);
					   $("#check"+id).attr("checked",false);
					   var value=$("#expressStyle"+id).html();
						  if("<font color=\"red\">已打印</font>"==value){
							  $("#pendPackForm_"+id).remove();
							  
						  }
					 
				} else {
					alert(data.content);
				}
			},
			error : function() {
				alert("服务器异常4");
			}
		});
	}
	
	
   function ajaxWorkTaskPackFormStatus(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxWorkTaskPackFormStatus',
			data : 'workIds=' + item,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					   var lists=workIds.split(":");
					
					  for(var i=0;i<lists.length;i++){
					     $("#check"+lists[i]).attr("disabled",true);
					     $("#check"+lists[i]).attr("checked",false);
					     var value=$("#expressStyle"+lists[i]).html();
						  if("<font color=\"red\">已打印</font>"==value){
							  $("#pendPackForm_"+lists[i]).remove();
							  
						  }
					  }
					 
				} else {
					alert(data.content);
				}
			},
			error : function() {
				alert("服务器异常5");
			}
		});
	}
	
	function printWorkBatch(taskName, printerName, printContent,rankno) {
		LODOP.PRINT_INIT(taskName);
        LODOP.ADD_PRINT_TEXT(10, 10, 300, 20, rankno);
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle+ printContent);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}

	function hideMessage() {
		$(function() {
			setTimeout(function() {
				$("#message").hide();
			}, 3000);
		});
	}
	
	
	function verify(content) {
		var result =content.match(expressRex);
		if(result==null){
		  return false;
		}
		return true;
	}
	
	function getAjaxExpress() {
       var expressStylesId = $("#expressStylesId").val();
 
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/getAjaxExpress',
			data : 'expressStylesId=' + expressStylesId,
			dataType : 'json',
			success : function(data) {
				$("#startWaybillNODiv").attr("style","display:inline;");
				if (data.status == "1") {
					expressRex=data.content.logisticsCompany.regMailNo;
					expressId=data.content.id;
					expressType=data.content.type;
					if("mail"==expressType){
					   //$("#firstExpressNumber").attr("readOnly","readOnly");
					   $("#startWaybillNODiv").attr("style","display:none;");
					}else if("MJZT" == data.content.logisticsCompany.companyCode){
						$("#firstExpressNumber").val("XN"+Math.round(Math.random()*8999999999+1000000000));
					}
				}  else if (data.status == "0") {
					//alert("获取运单号正则表达式错误！");
				}
			},

			error : function() {

			}
		});
	}

	function getAjaxPackformStyle() {
		var packformStylesId = $("#packformStylesId").val();
		if (packformStylesId == "" || packformStylesId == null) {
			alert("还没有这个随箱单");
			return;
		}
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/packformStyle/getAjaxPackformStyle',
			data : 'packformStylesId=' + $("#packformStylesId").val(),
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {

					packStyleName = data.name;
					packStyleType = data.type;
					packformStyleContent = data.content;
				} else if (data.status == "0") {
					alert("获取随箱单信息错误！");
				}

			},
			error : function() {
				alert("服务器异常6");
			}
		});
	}
	

	 
	  function ajaxExpressStyle(companyCode,areaGroupCode,customerCode,type) {
		    type=(type=="cbill"? "normal":"mail");
		   // packFormPrinter(expressStylesId);
		   // packFormPrinter(packFormPrinter);
			/* $.ajax({
				type : 'post',
				url : '${ctx}/v2/expressPrinting/ajaxExpressStyle',
				data : 'companyCode=' + companyCode+'&areaGroupCode='+areaGroupCode+'&customerCode='+customerCode+'&type='+type,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						var temp="<option value=''></option>";
						$.each(data.content,function(i,obj){
						       temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
						});
						
						$("[name='expressStylesId']").html(temp);
						$("[name='expressStylesId']").trigger("chosen:updated");
						getAjaxExpress();
					}  
				},

				error : function() {

				}
			}); */
			
		}
	  
	  function ajaxVerifyExpress(item) {
			$.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxVerifyExpress',
				data : 'taskCode=' + item,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						var temp="";
						$.each(data.content,function(i,obj){
						    temp+="<tr><td>"+(i+1)+"</td><td>"+obj.expressNo+"</td></tr>";
						    if(i==0){
						    	firstExpress=obj.expressNo;
						    }else{
						    	endExpress=obj.expressNo;
						    }
						});
						$("#tableVerify").html(temp);
					}  
				},

				error : function() {

				}
			});
			
		}
	  
	  function verifyExpressLists(item,type) {
			if("first"==type){
				if(item.value.trim()!=firstExpress){
					$("#firstSpan").html("<font color='red'>起始快递单号错误</font>");
				}else{
					$("#firstSpan").html("<font color='blue'>验证成功</font>");
					$("#endExpress").focus();
				}
			}else{
				if(item.value.trim()!=endExpress){
					$("#endSpan").html("<font color='red'>终止快递单号错误</font>");
				}else{
					$("#endSpan").html("<font color='blue'>验证成功</font>");
				}
			}
		}
	
	//------------------------------打印拣货单--------------------------------------------
	function AjaxPagePrinter(){
		printName = $("#pickPickPrint").val();
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/pickTask/ajaxPrintPickInfo',
			data : {
				taskCode:taskCode
			},
			dataType : 'json',
			success : function(data){
				if(data.status == "1"){
					//打印拣货单
					printPickInfo(data.taskItemList,data.workOrderList,printName);
					closeBg();
					$("#print_"+data.taskItemList[0].taskCode).attr("disabled",true);
				}else{
					alert("打印加载错误！");
				}
			}
		});
	}
	function printPickInfo(taskItem,workOrderList,printName){
		var taskCode = taskItem[0].taskCode;
		var adjustTop = 0;
	 	var adjustLeft = 0;
		var str = '';
		var num = 0;
		LODOP.PRINT_INIT(taskCode);
		LODOP.ADD_PRINT_BARCODE((15+adjustTop)+"mm", "65%", "45mm", "10mm", "128Auto", taskCode);
		str +="<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
		str +="<tr><td colspan= '7' align = 'center'><h3>拣货单(任务编号："+taskCode+")</h3></td></tr>";
		str +="<tbody align = 'center'><tr><td colspan= '2'>仓库</td><td colspan= '2'>"+taskItem[0].warehouseCode+"</td></tr>";
		str += "<tr style='font-size:10pt'><td width='7%'>序号</td><td width='10%'>商家</td><td width='18%'>库位</td><td width='18%'>箱位</td><td width='20%'>sku</td><td width='20%'>sku名称</td><td width='7%'>数量</td></tr>";
		for(var i =0;i<taskItem.length;i++){
			str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+taskItem[i].customerCode+"</td><td>"+taskItem[i].stockCode+"</td><td>"+taskItem[i].boxCode+"</td><td>"+taskItem[i].sku+"</td><td>"+taskItem[i].skuName+"</td><td>"+taskItem[i].num+"</td></tr>";
			num += taskItem[i].num;
		}
		str +="</tbody>";
		str +="<tfoot align = 'center'><tr><td colspan= '6'><h4>拣货单(任务编号："+taskCode+")</h4></td><td>"+num+"</td></tr></tfoot>";
		str +="</table>";
		LODOP.SET_PRINT_PAGESIZE(1, 0, 0,  $("#paperSizes").val()) ;
		LODOP.ADD_PRINT_TABLE(30,0, "100%","100%",str);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
		//美的打印拣货清单
		if("MID"==taskItem[0].customerCode){
			printPickDetailInfo(workOrderList,taskCode,printName);
		}
	}
	function printPickDetailInfo(workList,taskCode,printName){
		LODOP.PRINT_INIT(taskCode);
		var adjustTop = 0;
	 	var adjustLeft = 0;
		var str = '';
		str +="<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
		str +="<tr><td colspan= '4' align = 'center'><h3>拣货清单(任务编号："+taskCode+")</h3></td></tr>";
		str += "<tbody><tr style='font-size:10pt'><td width='6%'>序号</td><td width='47%'>任务号</td><td width='22%'>商品名</td><td width='25%'>sku</td></tr>";
		for(var i =0;i<workList.length;i++){
			var itemSize = workList[i].voItem.length;
			str +="<tr style='font-size:10pt' ><td rowspan='"+itemSize+"'>"+(i+1)+"</td><td rowspan='"+itemSize+"'>"+workList[i].taskCode+"</td>";
			for(var j =0;j<itemSize;j++){
				str +="<td>"+workList[i].voItem[j].goodName+"</td><td>"+workList[i].voItem[j].skuAndqty.split(":")[0]+"("+workList[i].voItem[j].skuAndqty.split(":")[1]+")</td></tr>";
			}
		}
		str +="</tbody>";
		str +="<tfoot align = 'center'><tr><td colspan= '4'><h4>拣货清单(任务编号："+taskCode+")</h4></td></tr></tfoot>";
		str +="</table>";
		LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A5") ;
		LODOP.ADD_PRINT_TABLE(30,0, "100%","100%",str);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
	}
</script>
</head>

<body>
<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="12" bgcolor="#8EB4CB">订单打印</th>
		</thead>
		
	    <tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">订单编号：</td>
		    <td colspan="9">
		      <input type="text"  id="txt_orderno" onchange="change_sku();"  style="margin-top: 10px; margin-left: 10px;"/>
		      <span style="margin-left:12px; margin-top: 10px; color: red;font-weight: bold;" id="msg_sku"></span>
		    </td>
		</tr>
		
		 <tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">扫描信息：</td>
		    <td colspan="9">
		      <textarea  id="txt_info" style="margin-top: 10px; margin-left: 10px; width: 800px;" readonly="readonly"></textarea>
		      <input type="button" value="清空"  class="btn btn-info" onclick="reset();" style="margin-top: 7px; margin-left: 10px;" />
		    </td>
		</tr>
		
		<!-- <tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">SKU编号：</td>
		    <td colspan="9" >
		      <span name="exist" style="display: none;">
		      <a id="btn_print_ebill" href="#printWorkBatchEbill" role="button" data-toggle="modal" class="btn" onclick="changeStatus('ebill');" >打印电子运单</a>
		      <a id="btn_print_cbill" href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn"   onclick="changeStatus('express');" >打印普通运单</a>
		      <a id="btn_print_boxbill" href="#printAllPackFormStyle" role="button" data-toggle="modal" class="btn"   onclick="changeStatus('packForm');" >打印随箱单</a>
		      <input type="button" value="包装完成"   id="btn_pkg" class="btn btn-primary" onclick="pkg();"/>
		      </span>
		    </td>
		</tr> -->
		
	</table>
	
	<!-- 运单信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="12" bgcolor="#8EB4CB">运单信息：</th>
		</thead>
		
		<tr name="noexist">
		     <td colspan="10" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		<thead name="exist" style="display: none;">
		    <th>订单编号</th>
			<th>运单编号</th>
			<th>快递公司</th>
			<th>省、市、区</th>
			<th>收货人</th>
			<th>联系手机</th>
			<th>联系座机</th>
			<th>收货人地址</th>
		</thead>
		
		<tr name="exist" style="display: none;">
		    <td id="orderno"></td>
		    <td id="expressNo"></td>
		    <td id="expressName"></td>
		    <td id="area"></td>
		    <td id="recena"></td>
		    <td id="mobile"></td>
		    <td id="teleph"></td>
		    <td id="address"></td>
		  </tr>
	</table>
	<input type="hidden" id="task_code" name="task_code" />
	<input type="hidden" id="orderno_code" name="orderno_code" />
	<!-- 订单详细信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="12" bgcolor="#8EB4CB">订单详细信息：</th>
		</thead>
		
		<tr name="noexist">
		     <td colspan="10" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		
		<thead name="exist" style="display: none;">
			<th>序号</th>
			<th>SKU</th>
			<th>数量</th>
		</thead>
		<tbody id="orderItems"></tbody>
	</table>	
<%-- <a href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-primary" onclick="ajaxExpressStyle('${task.companyCode }','${task.warehouseCode }','${task.customerCode}','${task.billType }');printInitExpress('${task.id}');" style="margin-left: 20px;" id="express_${task.id }"> 打印快递单 </a> --%>
<a href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-primary" onclick="ajaxExpressStyle('${task.companyCode }','${task.warehouseCode }','${task.customerCode}','${task.billType }');printInitExpress('${task.id}');initFirstExpress('${task.taskCode}');" style="margin-left: 20px;" > 打印电子单 </a>
<!-- id="express_${task.id }" -->
<%-- <a href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-primary"  onclick="changeStatus('${order.taskCode}','express','${order.warehouseCode}','${order.customerCode}');" style="margin-left: 20px;">打印快递单</a>
 --%>
		<div  class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printWorkBatchExpress">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto; height: 400px">
							<div class="form-group row">
							    <div class="col-sm-9">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 选择打印机: </span> 
										<select id="expressPrint" name="packFormPrinter"  class="form-control" >
										</select>
									</div>
								</div>
							</div>
							
							<div class="form-group row">
							    <div class="col-sm-9">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 选择快递单:</span> 
										<select id="expressStylesId" name="expressStylesId"   class="form-control" onchange="getAjaxExpress();">
											<option value=""></option>
										</select>
									</div>
								</div>
							</div>
						
						<c:if test="${order.billType ne 'ebill'}">
							<div class="form-group row">
							    <div class="col-sm-9" id = "startWaybillNODiv">
									<div class="input-group col-sm-12">
										<span class="input-group-text"> 起始运单号:</span> 
										<input type="text" id="firstExpressNumber"   class="form-control" />
									</div>
								</div>
							</div>
						</c:if>
							
							
					</div>
					  	<c:if test="${order eq null }">
			               <div class="modal-footer">
							<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrintExpress()"> 立即打印 </a>
							<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
						  </div>
			            </c:if>
						<c:if test="${order ne null }">
			               <div class="modal-footer">
							<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrinter('needExpressCompany')"> 立即打印 </a>
							<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
						  </div>
			            </c:if>
				</div>
			</div>
		</div>
		


		<div class="modal fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="printAllPackFormStyle">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						
						<h3 id="myModalLabel">
		                                                        打印随箱单信息
						</h3>
						<span id="messageLable"></span>
					</div>
					
					<div class="modal-body" style="height: 400px">
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 选择打印机: </span> 
									<select id="packFormStylePrint" name="packFormPrinter" class="form-control"  >
			
									</select>
								</div>
							</div>
						</div>
						
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 选择随箱单: </span> 
									<select id="packformStylesId" name="packformStyleId" class="form-control" onchange="getAjaxPackformStyle();">
										<c:forEach items="${packformStyles}" var="obj">
											<option value="${obj.id}"> ${obj.styleName} </option>
										</c:forEach>
									</select>
								</div>
							</div>
						</div>
					</div>
		
		           <c:if test="${order ne null }">
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrinter()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		           </c:if>
		           <c:if test="${order eq null }">
					<div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="printPackFormStyle()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					</div>
				  </c:if>
				</div>
			</div>
		</div>
		
		
		
		<div class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printGuarantee">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
		                                                        打印保修单信息
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto;height: 400px">
						<div class="control-group">
							<div class="controls">
								  选择打印机:
								<select id="guaranteeStylePrint" name="packFormPrinter" >
		
								</select>
							</div>
						</div>
					</div>
					
					
		
		           <c:if test="${order ne null }">
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="pageAjaxPrinter()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		           </c:if>
		           <c:if test="${order eq null }">
					<div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="printAjaxGuarantee()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					</div>
				  </c:if>
		  	</div>
		  </div>
		</div>
		<div class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printPickInfo">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
		                                                        打印拣货单信息
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto;">
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 选择打印机: </span> 
									<select id="pickPickPrint" name="pickPickPrint" class="form-control"  >
			
									</select>
								</div>
							</div>
						</div>
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
										<span class="input-group-text"> 纸张尺寸: </span> 
										<select id="paperSizes" name="paperSizes" class="form-control"  >
											<option value="A4" selected="selected" >A4</option>
											<option value="A5" >A5</option>
										</select>
								</div>
							</div>
						</div>
						
					</div>
					
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="AjaxPagePrinter()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		  	</div>
		  </div>
		</div>
		
</section>
		<script type="text/javascript">
	//getAjaxPackformStyle();
	getAjaxExpress();
	var status="";
	var taskCode="";
	function changeStatus(task,item,areaGroupCode,type){
		taskCode=task;
		status=item;
		if("packForm"==item){
			 packFormPrinter("packFormStylePrint");
			 ajaxCustomerCodePackformStyle(type);
		}else if("express"==item){
			 packFormPrinter("expressPrint");
			 ajaxGetAllExpress(type,areaGroupCode,'normal');
		}else if("ebill"==item){
			 packFormPrinter("expressPrint");
			 ajaxGetAllExpress(type,areaGroupCode,'mail');
		}else if("guarantee"==item){
			packFormPrinter("guaranteeStylePrint");
		}else if("pickInfo"==item){
			packFormPrinter("pickPickPrint");
		}
	}
	
	function pageAjaxPrinter(needExpressCompay){
		/* var esiValue = $("#expressStylesId").val();
		if(needExpressCompay && !esiValue){
			alert("请选择快递单");
			return;
		}
		
	    var orders='${order.order.ordeno}';
	    var taskcode='${order.taskCode}';
		   if(orders==""){
		    $("#message").html("请选择订单");
		    $("#message").show();
		    hideMessage();
		    return;
		   }
		   if("express"==status){
		    var firstExpressNumber = $("#firstExpressNumber").val();//运单号
			var expressStylesId = $("#expressStylesId").val();//快递单样式
			
			   printName=$("#expressPrint").val();
		        if(!verify(firstExpressNumber)){
		           alert("请输入正确的订单号！");
		           return;
		        }
		       ajaxPrintPackExpressOrdenos(orders,firstExpressNumber,expressStylesId);
		   }else if("packForm"==status){
			   printName= $("#packFormStylePrint").val();
		   		var packformStylesId = $("#packformStylesId").val();//随箱单样式
		   		packformName=$("#packformStylesId").text();
		        ajaxPrintPackFormOrdenos(orders,packformStylesId);
		   }else if("ebill"==status){
			   printName= $("#expressPrint").val();
			   var expressStylesId = $("#expressStylesId").val();//快递单样式
			  
			   ajaxPrintEBillExpress(orders,expressStylesId,taskcode);
		   }else if("guarantee"==status){
		   		printName = $("#guaranteeStylePrint").val(); //保修单
		   		ajaxPrintguaranteeOrdenos(orders);
		   } */
		   var expressStylesId = $("#expressStylesId").val();//快递单样式
		ajaxPrintEBillExpress(11,expressStylesId,T123456);
		
	}
	
	function ajaxPrintPackExpressOrdenos(ordenos,firstExpress,expressId){
		 showBg();
		$.ajax({
					type : 'post',
					url : '${ctx}/print/ajaxPrintPackExpressOrdenos',
					data : 'ordenos=' + ordenos+'&firstExpress='+firstExpress+'&expressId='+expressId,
					dataType : 'json',
					success : function(data) {
						 if (data.status == "1") {
							$.each(data.content, function(i) {
								
								    var str=data.content[i].content;
								    str=str.replace(/\r\n|\n|\r/g,"");								  
								printExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].taskName,data.content[i].expressNo,data.content[i].ordeno,data.content[i].companyCode);
								
							});
						    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
						       closeBg();
						} else if (data.status == "-3") {
					    	closeBg();
							alert("请输入正确的运单号！");
						} else if (data.status == "0") {
						    closeBg();
							alert("加载错误！");
						}

					},

					error : function() {

					}
				});
		}
	
	function ajaxPrintPackFormOrdenos(ordenos,packformStyleId){
		 showBg();
		$.ajax({
					type : 'post',
					url : '${ctx}/print/ajaxPrintPackFormOrdenos',
					data : 'ordenos=' + ordenos+'&packformStyleId='+packformStyleId,
					dataType : 'json',
					success : function(data) {
						 if (data.status == "1") {
							$.each(data.content, function(i) {
								
								 printStyle(packformName,data.content[i].taskName,printName,data.content[i].content,data.content[i].ordeno,data.content[i].expressNo,data.content[i].taskName);
								
							});
						    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
						      closeBg();
						} else if (data.status == "-3") {
					    	closeBg();
							alert("请输入正确的运单号！");
						} else if (data.status == "0") {
						    closeBg();
							alert("加载错误！");
						}

					},

					error : function() {
		                alert("服务器异常1");
					}
				});
		}
		
	function ajaxPrintguaranteeOrdenos(orders){
		showBg();
		printName = $("#guaranteeStylePrint").val();
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPrintguaranteeOrdenos',
			data : {
				ordenos:orders
			},
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					$.each(data.workOrders,function(i,v){
							printGuarantee(v,printName);
						});
					closeBg();
					} else {
						closeBg();
					}
				 }
		});
		}
	
	function ajaxCustomerCodePackformStyle(item) {
		$.ajax({
					type : 'post',
					url : '${ctx}/v2/packformStyle/ajaxCustomerCodePackformStyle',
					data : 'customerCode=' + item,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							var _temp="";
							$.each(data.content,function(i,obj){
							       _temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
							    });
							
							    $("#packformStylesId").html(_temp);
							    $("#packformStylesId").trigger("chosen:updated");
						} 
					},
					error : function() {

					}
				});
	}
	
	function ajaxGetAllExpress(item,areaGroupCode,type) {
		$.ajax({
					type : 'post',
					url : '${ctx}/v2/expressPrinting/ajaxGetAllExpress',
					data : 'customerCode=' + item+'&type='+type+'&areaGroupCode='+areaGroupCode,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							var _temp="<option value=''></option>";
							$.each(data.content,function(i,obj){
							       _temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
							    });
							
							    $("#expressStylesId").html(_temp);
							    $("#expressStylesId").trigger("chosen:updated");
						} 
					},
					error : function() {

					}
				});
	}
</script>
</body>
</html>
